package org.monster.uiboot;

import org.monster.context.util.URIUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

/**
 * 编译活动
 */
public class CompileAction extends ItemAction implements ActionListener {

    /**
     * 构造方法
     *
     * @param frame 片段
     */
    public CompileAction(Frame frame) {
        super(frame);
    }

    /**
     * 活动执行
     *
     * @param e 活动事件
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        jFileChooser.setCurrentDirectory(new File(System
                .getProperty("user.dir") + File.separator + "webapps"));
        int selectVal = jFileChooser.showOpenDialog(frame);
        if (selectVal == JFileChooser.APPROVE_OPTION) {
            String path = jFileChooser.getSelectedFile().getPath();
            URIUtils handler = new URIUtils();
            String webAppName = handler.endsWithURI(path, File.separator);
            StringBuffer buffer = new StringBuffer();
            buffer.append("{dos-(3)-").append(webAppName).append("}");
            receiver.receive(buffer.toString());
        }
    }
}
